package com.sunda.spmswms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sunda.spmswms.entity.SapPackageListDtl;
import com.sunda.spmswms.mapper.SapPackageListDtlMapper;
import com.sunda.spmswms.service.ISapPackageListDtlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * SAP装箱单明细表 服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-04-22
 */
@Service
public class SapPackageListDtlServiceImpl extends ServiceImpl<SapPackageListDtlMapper, SapPackageListDtl> implements ISapPackageListDtlService {


    @Override
    public List<SapPackageListDtl> getSapPackageListDtlsByWhsOutUuid(String whsOutUuid) {
        if(StringUtils.isEmpty(whsOutUuid)){
            return null;
        }
        return this.baseMapper.selectList(new QueryWrapper<SapPackageListDtl>().eq("WHS_OUT_UUID",whsOutUuid));
    }

    @Override
    public int updateSapPackageListDtl(String packageList, String targetStatus) {
        if (StringUtils.isEmpty(packageList) || StringUtils.isEmpty(targetStatus)){
            return -1;
        }
        SapPackageListDtl sapPackageListDtl = new SapPackageListDtl();
        sapPackageListDtl.setSpmsStatus(targetStatus);
        return this.baseMapper.update(sapPackageListDtl, new QueryWrapper<SapPackageListDtl>().eq("PACKAGE_LIST", packageList));
    }

    @Override
    public List<Map<String, Object>> getSapPackageList(String packageList) {
        if (StringUtils.isEmpty(packageList)){
            return null;
        }
        return this.baseMapper.getSapPackageList(packageList);
    }

    @Override
    public int updateSapPackageListDtl(String packageList, String item, String whsOutUuid) {
        SapPackageListDtl sapPackageListDtl = new SapPackageListDtl();
        sapPackageListDtl.setWhsOutUuid(whsOutUuid);
        QueryWrapper<SapPackageListDtl> queryWrapper = new QueryWrapper<SapPackageListDtl>().eq("PACKAGE_LIST", packageList).eq("ITEM", item);
        return this.baseMapper.update(sapPackageListDtl, queryWrapper);
    }

    @Override
    public List<Map<String, Object>> getWhsOutDtlX(String uuid, String goodsType) {
        return this.baseMapper.getWhsOutDtlX(uuid, goodsType);
    }

    @Override
    public int uSapPackageListDtl(String targetStatus, String whsOutUuid) {
        return this.baseMapper.uSapPackageListDtl(targetStatus, whsOutUuid);
    }

    @Override
    public int updateSapPackageListDtlM(SapPackageListDtl sapPackageListDtl, String packageList, String item) {
        QueryWrapper<SapPackageListDtl> queryWrapper = new QueryWrapper<SapPackageListDtl>().eq("PACKAGE_LIST", packageList).eq("ITEM", item);
        return this.baseMapper.update(sapPackageListDtl, queryWrapper);
    }

    @Override
    public int insertSapPackageListDtl(SapPackageListDtl sapPackageListDtl) {
        return this.baseMapper.insert(sapPackageListDtl);
    }

    @Override
    public int deleteUnplannedSapPackageListDtl(String whsOutUuid, String unplanned) {
        return this.baseMapper.delete(new QueryWrapper<SapPackageListDtl>().eq("WHS_OUT_UUID", whsOutUuid).eq("UNPLANNED", unplanned));
    }

    @Override
    public List<Map<String, Object>> getSapPackageListDtlM(String packageList) {
        return this.baseMapper.getSapPackageListDtlM(packageList);
    }
}
